//
// Created by Jisam on 31/08/2024 4:06 AM.
// Solution of  P1219 八皇后
// 2024-08-31 04:17:19 AC 100 记得开N*N的
//#pragma GCC optimize(3)
#include <bits/stdc++.h>

using namespace std;
#define endl "\n"
#define PSI pair<string,int>
#define PII pair<int,int>
#define PDI pair<double,int>
#define PDD pair<double,double>
#define VVI vector<vector<int>>
#define VI vector<int>
#define VS vector<string>
#define PQLI priority_queue<int, vector<int>, less<int>>
#define PQGI priority_queue<int, vector<int>, greater<int>>
#define code_by_jisam ios::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
typedef long long i64;
typedef unsigned u32;
typedef unsigned long long u64;
typedef __int128 i128;
int dx[] = {-1, 1, 0, 0, 1, 1, -1, -1,};
int dy[] = {0, 0, -1, 1, 1, -1, -1, 1,};
int n;
int ans;
const int MAXN = 105;
int a[MAXN],b[MAXN],c[MAXN],d[MAXN];
void dfs(int i){
    if(i > n){
        if(ans <= 2){
            for(int k = 1; k <= n ; k ++){
                cout << a[k] <<" ";
            }
            cout <<endl;
        }
        ans ++;
        return ;
    }
    else{
        for(int j = 1; j <= n; j ++){
            if(!(b[j] || c[i + j] || d[i - j  + n])) {
                a[i] = j;
                b[j] = 1;
                c[i + j] = 1;
                d[i - j + n] = 1;
                dfs(i + 1);
                b[j] = 0;
                c[i + j] = 0;
                d[i - j + n] = 0;
            }
        }
    }
}
void solution() {
    cin >> n;
    dfs(1);
    cout <<ans;
}

int main() {
    code_by_jisam;
    int T = 1;
//    cin >> T;
    while (T--) {
        solution();
    }
    return 0;
}